import 'package:enjoy_plus/models/home_noticelist_model.dart';
import 'package:enjoy_plus/utils/toast.dart';
import 'package:flutter/material.dart';

class HomeList extends StatelessWidget {
  HomeList({super.key, required this.notifyList});

  final List<NotifyItem> notifyList;

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.only(top: 10),
      child: Column(
        children: [
          Row(children: [
            Image.asset(
              'assets/images/notice@2x.png',
              width: 24,
            ),
            const Text('社区',
                style: TextStyle(
                    fontSize: 16,
                    fontWeight: FontWeight.bold,
                    color: Colors.black)),
            const Text('公告',
                style: TextStyle(
                    fontSize: 16,
                    fontWeight: FontWeight.bold,
                    color: Colors.orange))
          ]),
          ListView(
            shrinkWrap: true,
            physics: const NeverScrollableScrollPhysics(),
            children: notifyList
                .map((item) => GestureDetector(
                    onTap: () {
                      // 跳转详情页
                      Navigator.pushNamed(context, '/noticeDetail',
                          arguments: item.id);
                    },
                    child: NotifyItemWidget(item: item)))
                .toList(),
          )
        ],
      ),
    );
  }
}

class NotifyItemWidget extends StatelessWidget {
  final NotifyItem item;
  const NotifyItemWidget({super.key, required this.item});

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      height: 180,
      margin: const EdgeInsets.only(bottom: 10, top: 16),
      padding: const EdgeInsets.all(10),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(10),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text(item.title,
              style: const TextStyle(
                  fontSize: 16,
                  fontWeight: FontWeight.bold,
                  color: Colors.black),
              overflow: TextOverflow.ellipsis,
              maxLines: 1),
          Text(
            item.content,
            style: const TextStyle(
                fontSize: 14, color: Color.fromARGB(255, 153, 153, 153)),
            overflow: TextOverflow.ellipsis, // 超出范围后显示...
            maxLines: 5, // 限制最大行数
          ),
          Text(item.createdAt,
              style: const TextStyle(
                  fontSize: 12, color: Color.fromARGB(255, 153, 153, 153)),
              overflow: TextOverflow.ellipsis,
              maxLines: 1)
        ],
      ),
    );
  }
}
